{aide_template 'common/header'}
<link href="{$aideUrl}web/resource/css/util.min.css" rel="stylesheet">
<script type="text/javascript" src="{$aideUrl}web/resource/js/util.min.js?v=20170912"></script>
<style>
    .label-default{background-color:#d1dade;color:#5e5e5e;}
    .input-group-addon .radio-inline, .input-group-addon .checkbox-inline{padding-top:0; line-height:0.95;}
    .dropdown-menu{ min-width:145px; }
    .multi-img-details .multi-item{height:auto;}
    #member.multi-img-details .multi-item{text-align:center; max-width:100px;}
    #member.multi-img-details .multi-item img{ max-width:90px; max-height:90px;}
    #member.multi-img-details .multi-item .title{ overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
    #myTab2.nav-tabs{border-color: #1ab394;}
    #myTab2.nav-tabs>li>a{border-radius:0!important;padding: 7px 15px;}
    #myTab2.nav-tabs>li>a:hover{ color:#333}
    #myTab2.nav-tabs>li.active>a, #myTab2.nav-tabs>li.active>a:hover, #myTab2.nav-tabs>li.active>a:focus{color: #FFF;border-radius:0;background-color: #1ab394;border-color: #1ab394;}
    #options.markethide .optmarket, .markethide.market{display:none}
    .img_show{width: 150px;height: 100px;}
</style>
<link href="{$_W['siteroot']}web/resource/components/select2/select2.min.css" rel="stylesheet">
{if $op == 'post'}
<ol class="breadcrumb we7-breadcrumb" style="display:none">
    <a href="./index.php?c=site&amp;a=article&amp;"><i class="wi wi-back-circle"></i> </a>
    <li><a href="./index.php?c=site&amp;a=article&amp;">视频管理</a></li>
    <li><a href="./index.php?c=site&amp;a=article&amp;do=post&amp;">视频编辑</a></li>
</ol>
<ul class="nav nav-tabs" id="myTab">
    <li class="active"><a href="#tab_basic">视频编辑</a></li>
</ul>

<div class="main">
    <form action="" method="post" onsubmit="return check(this)" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="videoid" value="{$videoid}"/>
        <div class="tab-content" style="height: 500px">
            <div class="tab-pane in active" id="tab_basic">
                <div class="panel panel-default">
                    <div class="panel-heading">基本设置</div>
                    <div class="panel-body">
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">视频标题</label>
                            <div class="col-sm-6 col-xs-12">
                                <input type="text" name="video[title]" class="form-control" value="{$video['title']}" placeholder="视频标题"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">视频</label>
                            <div class="col-sm-9 col-xs-12">
                                <input type="hidden" name="thumb_old" value="{$video['file_path']}">
                                {php echo tpl_form_field_video('video[file_path]', $video['file_path']);}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">视频点击量(初始)</label>
                            <div class="col-sm-6 col-xs-12">
                                <input type="text" name="video[hits]" class="form-control" value="{$video['hits']}" placeholder="视频点击量"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">是否推荐</label>
                            <div class="col-xs-12 col-sm-5">
                                <label class="radio radio-inline">
                                    <input type="radio" name="video[recom]" value="1"{if $video['recom']} checked{/if}> 是
                                </label>
                                <label class="radio radio-inline">
                                    <input type="radio" name="video[recom]" value="0"{if !$video['recom']} checked{/if}> 否【默认否】
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group" style="text-align:center;">
            <div class="col-xs-12">
                <input name="submit" type="submit" value="　　保存　　" class="btn btn-primary"/>
                <input type="hidden" name="token" value="{$_W['token']}"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        window.optionchanged = false;
        //
        $(".js-atype input[name='video[atype]']").click(function(){
            var obj = $(this);
            if (obj.val()!='2'){
                $("#options").addClass('markethide');
                $(".market").addClass('markethide');
            }else{
                $("#options").removeClass('markethide');
                $(".market").removeClass('markethide');
            }
        });
        //
        $(".js-kefu input[name='video[kefu][type]']").click(function(){
            var obj = $(this);
            if (obj.val()!='2'){
                $(".kefu-url").hide();
                $(".kefu-qrcode").show();
            }else{
                $(".kefu-url").show();
                $(".kefu-qrcode").hide();
            }
        });
    });
    function check(form) {
        var id="{$videoid}",mid="{MERCHANTID}",proreview="{php echo $_W['_config']['proreview']==1 || ($_W['_config']['proreview']==2 && $video['aprice']==0)?1:0;}";
        if (id!='' && proreview=='0' && mid!=''){
            if(!confirm('修改后将进入审核状态，是否确认？')) {
                return false;
            }
        }else{
            return true;
        }
    }
</script>
{elseif $op == 'display'}
<form class="form-horizontal" action="" method="post">
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="panel-title">活动列表<span class="color-default pull-right">【点击活动标题复制连接】</span></div>
        </div>
        <div class="table-responsive">
            <table class="table table-hover table-bordered">
                <thead class="navbar-inner">
                <tr>
                    <th class="text-center" style="width:40px;">
                        <input type="checkbox" name="checkall" value="" id="checkall" onClick="var ck = this.checked; $(':checkbox').each(function(){this.checked = ck});">
                    </th>
                    <th class="text-center" style="width:40px;">ID</th>
                    <th class="text-left">活动标题</th>
                    <th class="text-left">视频</th>
                    <th class="text-left">视频图片</th>
                    <th class="text-center" style="width:330px;">操作</th>
                </tr>
                </thead>
                <tbody style="text-align: center;">
                    {loop $video $item}
                    <tr>
                        <td class="text-center"><input type="checkbox" name="check" value="{$item['id']}" class="items"></td>
                        <td>{$item['id']}</td>
                        <td class="text-left">{$item['title']}</td>
                        <td class="text-left">
                            <video width="200" height="100" id="video{$item['id']}" src="{php echo tomedia($item['file_path'])}" controls="controls"></video></td>
                        <td class="text-left">
                            <input class="cut" type="button" value="截图"  id="buttons_cut" onclick="cut({$item['id']})">
                            <input class="cut" type="button" value="上传" onclick="upload({$item['id']})">
                            {if !empty($item['img'])}
                            <img src="{$item['img']}" class="img_show" id="img_show{$item['id']}" alt="">
                            <canvas id="canvas{$item['id']}" style="display:none;"></canvas>
                            {else}
                            <canvas id="canvas{$item['id']}" style="display:block;"></canvas>
                            {/if}
                            <input type="hidden" id="img{$item['id']}">

                        </td>
                        <td class="text-center">
                            <div class="btn-group">
                                <a href="{php echo web_url('video/video/post', array('videoid' => $item['id']))}" class="btn btn-success btn-sm">编辑</a>
                                <a href="javascript:void(0);" class="js-delete btn btn-danger btn-sm" data-id="{$item['id']}">删除</a>
                            </div>
                        </td>
                    </tr>
                    {/loop}
                </tbody>
            </table>
        </div>
    </div>
    <div class="pull-right">{$pager}</div>
</form>
<script>
    // 使用canvas对视频进行截图
    function cut(id){
        var canvas = document.getElementById('canvas'+id+'');
        var video = document.getElementById('video'+id+'');
        canvas.width = 150;
        canvas.height = 100;
        var ctx = canvas.getContext('2d');
        ctx.drawImage(video, 0, 0,150,100);
        var base64 = canvas.toDataURL('images/png');
        document.getElementById('img'+id+'').value=base64;
        document.getElementById('img_show'+id+'').style='display:none';
        canvas.style='display:block';
    }
    function upload(id){
        var img=document.getElementById('img'+id+'').value;
        $.post("{php echo web_url('video/video/pass')}", {id:id, img:img}, function(data) {
            util.tips('修改成功');

        }, 'json');
    }
    //删除效果b，单条操作
    $('.js-delete').click(function(e) {
        e.stopPropagation();
        var $this = $(this);
        var videoid = $this.data('id');
        util.nailConfirm(this, function(state) {
            if (!state) return;
            $.post("{php echo web_url('video/video/delete')}", {videoid : videoid}, function(data) {
                if(!data.errno){
                    $this.parents('tr').remove();
                }
                util.tips(data.message);
            }, 'json');
        }, {html:"确定删除？",placement: $this.data('placement')});
    });
</script>
{/if}
{aide_template 'common/footer'}
